﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using DevComponents.DotNetBar;

namespace HYWJ.jxgl
{
    public partial class TKGLForm : Office2007Form
    {
        private DataSet dataSet = null;
        private SqlDataAdapter dataAdapter = null;

        public TKGLForm()
        {

            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            DialogResult result;
            result = MessageBox.Show("您确定要保存修改过的数据吗?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            if (result == DialogResult.Yes)
            {
                try
                {
                    //自动生成用修改的Command命令
                    SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter);
                    //将数据集中Teacher 表的数据提交给数据库更新
                    dataAdapter.Update(dataSet, "Question");
                    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

        }

        private void TKGLForm_Load_1(object sender, EventArgs e)
        {
            DataBase.OpenDataBase();

            string sql = "select question,optionA,optionB,optionC,optionD,Answer,SubjectId,QuestionID from Question ";
            //创建数据集对象
            dataAdapter = new SqlDataAdapter(sql, DataBase.connection);
            //创建数据集对象
            dataSet = new DataSet("shenyang");
            //填充数据集
            dataAdapter.Fill(dataSet, "Question");
            dataGridView1.DataSource = dataSet.Tables["Question"];
            
        }

    }
}
